#include "common.h"

int main(int argc, char const *argv[])
{
    int port = 3000;
    int listen_fd = tcp_server_listen(port);
    struct sockaddr_in client;
    socklen_t clilen;

    printf("listening at localhost:%d\n", port);
    // 循环处理请求
    for (;;)
    {
        clilen = sizeof(client);
        int connfd = accept(listen_fd, (struct sockaddr *)&client, &clilen);
        char buf[20] = "Hello World!";
        write(connfd, buf, 20);
        char buffer[512];
        readn(connfd, buffer, 512);
        printf("received: %s\n", buffer);
        close(connfd);
    }
    return 0;
}
